﻿// C# 1.0 至 11.0 所有历史版本主要特性一句话汇总（2022/05/02更新）
// https://blog.csdn.net/weixin_43145361/article/details/94714976

// See https://aka.ms/new-console-template for more information
// Top-level statements
using CSharpNewFeatures;




while (true)
{
    Console.WriteLine("***************************************");
    Console.WriteLine("*  c. Common Operations               *");
    Console.WriteLine("*  3. C# 3.0                          *");
    Console.WriteLine("*  4. C# 4.0                          *");
    Console.WriteLine("*  7. C# 7.0                          *");
    Console.WriteLine("*  8. C# 8.0                          *");
    Console.WriteLine("*  9. C# 9.0                          *");
    Console.WriteLine("*  x. C# 10.0                         *");
    Console.WriteLine("*  e. Exit                            *");
    Console.WriteLine("***************************************"); 

    
    var input = Console.ReadLine();
    if (string.IsNullOrEmpty(input) || input.ToLower() == "e")
        break;

    CsharpDemoBase? csdemo = input.ToLower() switch
    {
        "c" => new CsharpCommon(),
        "3" => new CsharpDemo3(),
        "4" => new CsharpDemo4(),
        "7" => new CsharpDemo7(),
        "8" => new CsharpDemo8(),
        "9" => new CsharpDemo9(),
        "x" => new CsharpDemo10(),
        _ => null, 
    };

    if (csdemo == null)
    {
        var tom = new { ID = 0, Name = "Tom" };
        Console.WriteLine($"{tom.ID}, {tom.Name}");

        // 可空类型 s?.Length ==> if(s != null) len = s.Length
        // 所以需要考虑为空时的情况，故使用 ?? 进行为空时的赋值
        string? s = null;
        int len = s?.Length ?? 0;
        

        Console.WriteLine("Exit.");
    }

    csdemo?.Run();

    Console.WriteLine("\n");
}


// new CsharpDemo8().Run();


//foreach (var file in Directory.GetFiles("."))
//{
//    FileInfo fi = new FileInfo(file);
//    if (!fi.Exists || fi.Length > 10 * 1024)
//        continue;
//    Console.WriteLine(file);
//    var lines = File.ReadAllLines(file);
//    foreach (var line in lines)
//        Console.WriteLine("\t" + line);
//}

//
//new CsharpDemo7().Run();

// new Demo_MultiThreading().Run();
//new Demo_PeriodicTimer().Run();



 